package cn.tedu.config;

import cn.tedu.interceptor.ImageInterceptor;
import cn.tedu.interceptor.JWTInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * 配置MVC拦截器
 * @author Kiven
 */
@Configuration
public class MyWebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private JWTInterceptor jwtInterceptor;

    @Autowired
    private ImageInterceptor interceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        // 黑名单
        List<String> pathPatterns = new ArrayList<>();
        pathPatterns.add("/a");
        //白名单
        List<String> pathExcludePatterns = new ArrayList<>();
        pathExcludePatterns.add("/admin/*");
        // 缩略图路径
        pathExcludePatterns.add("/thumbnail/*");
        pathExcludePatterns.add("/sps/upload/*");
        pathExcludePatterns.add("/shop/**");
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns(pathPatterns)
        .excludePathPatterns(pathExcludePatterns);

        registry.addInterceptor(interceptor).addPathPatterns("/thumbnail/*");

        super.addInterceptors(registry);
    }
}
